package edu.java.homework.hw03.ipj06;

// TODO: organize imports (Ctrl+Shift+O)
import java.util.Arrays;

/**
 * Realization of visiting of all elements of matrix in diagonal (bottom->
 * top)starting from the element a[0][0]
 * 
 * @author Tsvetan Vasilev
 * 
 */

public class Exer04 {
    // Perfect implementation :) Congratulations :)
    /**
     * @param args
     */
    public static void main(String[] args) {
	int[][] matrix = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 },
		{ 13, 14, 15, 16 }

	};
	int length = matrix.length;
	// print the array
	for (int i = 0; i < length; i++) {
	    for (int j = 0; j < length; j++) {
		System.out.print(matrix[i][j] + "\t");
	    }
	    System.out.println();
	}

	// visit the elements in diagonals (bottom->top) starting from a[0][0]
	System.out.println("\n\nPrint the visiting of elements: ");
	for (int i = 0; i < length; i++) {
	    int k = i;
	    for (int j = 0; j <= i; j++, k--) {
		System.out.print(matrix[k][j] + "\t");
	    }
	    System.out.println();
	}

	for (int j = 1; j < length; j++) {
	    int l = j;
	    for (int i = length - 1; i >= j; i--, l++) {
		System.out.print(matrix[i][l] + "\t");
	    }
	    System.out.println();
	}

    }

}
